package day5;


import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTestFanxing {
    public static void main(String[] args) {
        //Map泛型
        //Collections.max()
        Map<String, String> m = new HashMap<>();//类型自动推导！！！
        m.put("cat", "猫");
        m.put("dog", "狗");
        m.put("tiger", "老虎");
        m.put("goldenfish", "金鱼");
        m.put("tiger", "华南虎");
        m.put("table", "桌子");
        m.put("desk", "桌子");
        m.put("nothing", null);
        m.put(null, "zero");//?
        m.put("two", "2");
        System.out.println("所有的key：？");
        Set<String> set = m.keySet();
        System.out.println(set);
        System.out.println("所有的value:");
        Collection<String> values = m.values();
        System.out.println(values);
        System.out.println("迭代：");
        Set<Map.Entry<String, String>> entries = m.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> next = iterator.next();
            String key = next.getKey();
            String value = next.getValue();
            System.out.println(key + "," + value);
        }
        Scanner in = new Scanner(System.in);
        System.out.print("请输入中文：");
        String zhong = in.next();
        if(!m.containsValue(zhong)){
            System.out.println("没有！");
            return;
        }
        Iterator<String> ir2 = m.keySet().iterator();
        while (ir2.hasNext()){
            String k=ir2.next();
            String v=m.get(k);
            if(zhong.equals(v)){
                System.out.println(k+" 就是你找的");
            }
        }

    }
}
